<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">  
<html>  
<head>  
<meta http-equiv="Content-Type" content="text/html; charset=GBK">  
<title>Chart</title>  
<script type="text/javascript" src="js/jquery-2.0.3.js"></script>  
<script type="text/javascript">  
var ws = null;  
function startWebSocket() {  
    if (!window.WebSocket) {
    	alert("WebSocket not supported by this browser!");  
    }
    // 创建WebSocket  
    ws = new WebSocket("ws://192.168.15.118:8080/oss/mywebsocket.do");  
    // 收到消息时在消息框内显示  
    ws.onmessage = function(evt) {     
        $('#msgBox').append(evt.data);  
        $('#msgBox').append('</br>');  
    };  
    // 断开时会走这个方法  
    ws.onclose = function() {   
        alert('close~~~~~~~');  
    };  
    // 连接上时走这个方法  
    ws.onopen = function() {     
        alert('open~~~~~~~~');   
    };  
}  
    
// 发送消息  
function sendMsg() {  
    var data = document.getElementById('msgSendBox').value;  
    ws.send(data);  
    document.getElementById('msgSendBox').value = '';  
      
}  
</script>  
</head>  
<body onload="startWebSocket();">  
<div id="msgBox" style="width:400px;height:300px;border:1px solid #000000">  
</div>  
<textarea id="msgSendBox" rows="5" cols="32"></textarea>  
<input type="button" value="send" onclick="sendMsg()"></input>  
</body>  
</html>  